﻿using Microsoft.Extensions.Logging;
using ST.Common.Util;
using ST.Common.Util.Text;
using ST.Common.Util.Xml;
using ST.WX.Common.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Web;
using System.Xml;

namespace ST.WX.Common.Pay
{
	/// <summary>
	/// 订单查询请求数据
	/// </summary>
	public class WXPayOrderQueryData : WXPayData
	{
		/// <summary>
		/// 商户订单号
		/// </summary>
		[Required]
		[Display(Name = "商户订单号")]
		[StringLength(32)]
		public string out_trade_no { get; set; }

		/// <summary>
		/// 微信订单号
		/// </summary>
		[Required]
		[Display(Name = "微信订单号")]
		[StringLength(32)]
		public string transaction_id { get; set; }

		public WXPayOrderQueryData() : base()
		{
		}

		public WXPayOrderQueryData(string appID, string mchID, string mchKey, WXPaySignType signType, string outTradeNo) : base(appID, mchID, mchKey, signType)
		{
			out_trade_no = outTradeNo;
		}

		public override void Validate()
		{
			base.Validate();

			if (string.IsNullOrEmpty(out_trade_no) && string.IsNullOrEmpty(transaction_id))
			{
				throw new WXPayException("订单查询接口中，out_trade_no、transaction_id至少填一个");
			}
		}

		public override SortedDictionary<string, object> ConvertFromObj()
		{
			SortedDictionary<string, object> values = new SortedDictionary<string, object>();
			values["out_trade_no"] = out_trade_no;
			values["transaction_id"] = transaction_id;
			return values;
		}
	}
}
